<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // 题目描述:有一组版本号如下['0.1.1', '2.3.3', '0.302.1', '4.2', '4.3.5', '4.3.4.5']。现在需要对其进行排序，排序的结果为 ['4.3.5','4.3.4.5','2.3.3','0.302.1','0.1.1']

    let versions =  ['0.1.1','0.1.1', '2.3.3','2.3', '0.302.1', '4.2', '4.3.4', '4.3.4.5']

    versions.sort((a,b)=>{
      let arr1 = a.split(".")
      let arr2 = b.split(".")
      let i = 0
      while(true){
        let s1 = arr1[i]
        let s2 = arr2[i]
        if(s1 && s2 && s1!=s2){
          return s2 - s1
        }
        if(!s1 || !s2){
          // return s1 ? -1 : 1
          return arr2.length - arr1.length;
        }
        i++
      }
    })
    console.log(versions)
  </script>
</body>
</html>